package aeso.br.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import aeso.br.model.Compra;
import aeso.br.model.Produto;
import aeso.br.util.HibernateUtil;

public class CompraDAO {
	
	public void add (Compra compra){
		 Session session = HibernateUtil.getSession().openSession();
	        Transaction t = session.beginTransaction();
	        session.save(compra);
	        t.commit();
		
	}

	public Compra getCompra (int id){
		
		Session session = HibernateUtil.getSession().openSession();
		return (Compra) session.load(Compra.class, id);
		
		
	}
	
	public List<Compra> listarCompra(){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		List lista  = session.createQuery("from Compra").list();
		t.commit();
		return lista;
		
	}
	
	public void remover(Compra compra){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		session.delete(compra);
		
	}
	
	public void alterar (Compra compra){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		session.update(compra);
		t.commit();
		
		
	}


}
